/*
 * @Description: 
 * @Author: paddies
 * @Date: 2024-06-27 12:43:53
 * @LastEditors: paddies
 * @LastEditTime: 2024-11-09 11:56:05
 * @FilePath: /shared_components/lib/luntai-components/build-sh-handle/buildShHandle.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:shared_components/build-button/buildButton.dart';
import 'package:shared_components/build-common/buildCommon.dart';
import 'package:shared_components/build-image/buildImage.dart';
import 'package:shared_components/build-input/buildInput.dart';
import 'package:shared_components/build-radio/buildRadio.dart';
import 'package:shared_components/build-select/buildSelect.dart';
import 'package:shared_components/build-upload/buildUpload.dart';
//  hasDeliveryType() {
//     var deliveryType = state.deliveryTypes.value.join(",");
//     return deliveryType;
//   }

refundTypeName(String code) {
  var res = '--';
  switch (code) {
    case "1":
      res = "退货退款";

      break;
    case "2":
      res = " 退换货";

      break;
    case "3":
      res = "三包申请";

      break;
    default:
  }

  return res;
}

final TextEditingController refundTypeInputController = TextEditingController();
final TextEditingController tireSizesInputController = TextEditingController();

final TextEditingController useReduceInputController = TextEditingController();
final TextEditingController selfOrderNoInputController =
    TextEditingController();
final TextEditingController logisticNumberInputController =
    TextEditingController();
final TextEditingController gapAmountInputController = TextEditingController();
final TextEditingController returnAmountInputController =
    TextEditingController();
final TextEditingController useReduceFeeInputController =
    TextEditingController();

buildShHandle(
    {dynamic item,
    String ruleUrl = '',
    required Function doGetDict,
    required Function doSupplyVerify,
    Function? handleDetailApi,
    Function? threeSafeHandleApi,
    Function? successFn}) async {
  print("内部数据====");
  print(item);
  //三包的处理
  if (showText(item["refundType"]) == '3') {
    buildSbShHandle(
        item: item,
        ruleUrl: ruleUrl,
        handleDetailApi: handleDetailApi,
        doGetDict: doGetDict,
        doSupplyVerify: doSupplyVerify,
        threeSafeHandleApi: threeSafeHandleApi,
        successFn: successFn);
    return;
  }
  //处理 方式
  var orderRefundStatus = [].obs;
  var orderRefundStatusList = [
    {"label": "受理", "value": "1"},
    {"label": "拒绝", "value": "2"}
  ].obs;
  //客服意见
  var reviewRemark = ''.obs;
  var refundImgUrl = [].obs;

  //配送类型
  var deliveryTypes = [].obs;
  //自配单号
  var selfOrderNo = "".obs;

  //物流公司
  var logisticCompanySn = [].obs;
  var logisticCompany = "".obs;
  var logisticCompanyList = [].obs;
  //物流单号

  var logisticNumber = ''.obs;
  //物流备注
  var remark = "".obs;

  var quantity = int.parse(showText(item["quantity"])) ?? 0;

  var tireSizes = [].obs;
  for (var i = 0; i < quantity; i++) {
    tireSizes.value.add("");
  }
  var l = await doGetDict(code: "logistic_company_type") as List;
  logisticCompanyList.value = l.map((e) {
        return {
          "label": showText(e["dictLabel"]),
          "value": showText(e["dictCode"])
        };
      }).toList() ??
      [];

  refundTypeInputController.text = refundTypeName(showText(item["refundType"]));

  //  var screenBottomHeight =
  // double.parse(GlobalPrefs.getValue("screenBottomHeight"));
  var screenBottomHeight = MediaQuery.of(Get.overlayContext!).padding.bottom;
  Get.bottomSheet(
      isScrollControlled: true,
      Container(
        padding: EdgeInsets.only(left: 10, right: 10, top: 20),
        decoration: new BoxDecoration(
          color: Colors.white,
          // new Radius.circular(20.0)
          borderRadius: new BorderRadius.only(
              topLeft: new Radius.circular(20.0),
              topRight: new Radius.circular(20.0)), //圆角
        ),
        height: 600,
        child: Obx(() => Container(
            width: double.infinity,
            height: double.infinity,
            // color: Colors.red,
            child: Column(
              children: [
                Container(
                  width: double.infinity,
                  alignment: Alignment.center,
                  child: Text(
                    "售后处理",
                    style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                  ),
                ),
                Expanded(
                    child: Container(
                  width: double.infinity,
                  height: double.infinity,
                  color: Colors.white,
                  child: SingleChildScrollView(
                      child: Column(
                    children: [
                      // Text(showText(state.orderRefundStatus.value)),
                      buildInput(
                          required: false,
                          title: "申请类型",
                          disabled: true,
                          textEditingController: refundTypeInputController,
                          labelWidth: 130,
                          value: refundTypeName(showText(item["refundType"])),
                          onChanged: (v, n) {
                            // orderRefundStatus.value = v;
                          }),
                      buildSelect(
                          required: true,
                          title: "处理方式",
                          value: orderRefundStatus.value,
                          onChanged: (v, n) {
                            orderRefundStatus.value = v;
                          },
                          multiple: false,
                          list: orderRefundStatusList.value),

                      Visibility(
                          visible: showText(item["refundType"]) != "1" &&
                              orderRefundStatus.value.join(",") != "2",
                          child: buildSelect(
                              required: true,
                              title: "配送类型",
                              value: deliveryTypes.value,
                              onChanged: (v, n) {
                                deliveryTypes.value = v;
                              },
                              multiple: false,
                              list: [
                                {"value": "1", "label": "物流"},
                                {"value": "2", "label": "自配"}
                              ])),
                      Visibility(
                          visible: showText(item["refundType"]) != "1" &&
                              orderRefundStatus.value.join(",") != "2",
                          child: Visibility(
                              visible: deliveryTypes.value.join(",") == '2',
                              child: buildInput(
                                  required: true,
                                  title: "自配单号",
                                  value: selfOrderNo.value,
                                  onChanged: (v) {
                                    selfOrderNo.value = v;
                                  }))),

                      Visibility(
                          visible: showText(item["refundType"]) != "1" &&
                              orderRefundStatus.value.join(",") != "2",
                          child: Visibility(
                              visible: deliveryTypes.value.join(",") == '1',
                              child: buildSelect(
                                  required: true,
                                  title: "物流公司",
                                  value: logisticCompanySn.value,
                                  onChanged: (v, n) {
                                    logisticCompanySn.value = v;
                                    logisticCompany.value = n;
                                  },
                                  multiple: false,
                                  list: logisticCompanyList))),

                      Visibility(
                        visible: showText(item["refundType"]) != "1" &&
                            orderRefundStatus.value.join(",") != "2",
                        child: Visibility(
                            visible: deliveryTypes.value.join(",") == '1',
                            child: buildInput(
                                required: true,
                                title: "物流单号",
                                value: logisticNumber.value,
                                onChanged: (v) {
                                  logisticNumber.value = v;
                                })),
                      ),

                      ...tireSizes.value.asMap().keys.map((i) {
                        return Visibility(
                            visible: showText(item["refundType"]) != "1" &&
                                orderRefundStatus.value.join(",") != "2",
                            child: buildInput(
                                required: true,
                                height: 120,
                                labelHeight: 50,
                                title: "胎码",
                                value: tireSizes.value[i],
                                type: "textArea",
                                direction: "ttb",
                                inputFormatters: [
                                  FilteringTextInputFormatter.deny(RegExp(',')),
                                  FilteringTextInputFormatter.deny(RegExp('，'))
                                ],
                                placeholder: "请输入胎码",
                                onChanged: (v) {
                                  tireSizes.value[i] = v;
                                  // state.tireSizes.value[i] = v;
                                }));
                      }).toList(),

                      buildInput(
                          title: "客服意见",
                          labelHeight: 50,
                          height: 180,
                          type: "textArea",
                          maxLines: 3,
                          direction: "ttb",
                          value: reviewRemark.value,
                          onChanged: (v) {
                            reviewRemark.value = v;
                          }),
                      Container(
                        width: double.infinity,
                        height: 50,
                        alignment: Alignment.centerLeft,
                        padding: EdgeInsets.only(left: 10),
                        child: Text(
                          "处理结果",
                          style: TextStyle(fontSize: 18),
                        ),
                      ),

                      buildUpload(
                          list: refundImgUrl,
                          rowCount: 2,
                          max: 4,
                          onChange: (type, value, index) {
                            if (type == 'add') {
                              print("添加返回");

                              refundImgUrl.add(value);
                            }
                            if (type == 'del') {
                              refundImgUrl.removeAt(index);
                            }
                            if (type == 'change') {
                              refundImgUrl[index] = value;
                            }
                          }),
                    ],
                  )),
                )),
                GestureDetector(
                  onTap: () {
                    Get.toNamed("/webview",
                        arguments: {"title": "《理赔标准》", "url": ruleUrl});
                  },
                  child: Container(
                    width: double.infinity,
                    height: 50,
                    alignment: Alignment.topCenter,
                    child: Text(
                      "《理赔标准》",
                      style: TextStyle(fontSize: 25, color: Color(0xff0000e9)),
                    ),
                    color: Colors.transparent,
                  ),
                ),
                Container(
                  width: double.infinity,
                  height: 80,
                  color: Colors.white,
                  child: Row(
                    children: [
                      Expanded(
                          child: Container(
                        width: double.maxFinite,
                        height: double.infinity,
                        color: Colors.white,
                        padding: EdgeInsets.only(
                            top: 10, bottom: 10, left: 10, right: 10),
                        child: buildButton(
                            title: "确定",
                            onClick: () async {
                              var _refundOrderNo =
                                  showText(item["refundOrderNo"]);
                              var _orderRefundStatus =
                                  orderRefundStatus.value.join(",");
                              var _reviewRemark = reviewRemark.value;

                              var _refundImgUrl = refundImgUrl.value.join(",");

                              var _deliveryType = deliveryTypes.value.join("");
                              var _selfOrderNo = selfOrderNo.value;

                              var _logisticNumber = logisticNumber.value;
                              var _logisticCompanySn =
                                  logisticCompanySn.value.join("");

                              var _refundType = showText(item["refundType"]);

                              // doSupplyVerify()
                              // var orderNo = showText(order["orderNo"]);
                              // var userId = showText(selectItem.value["id"]);
                              if (_orderRefundStatus == '') {
                                EasyLoading.showToast("请选择处理方式");
                                return;
                              }

                              if (_refundType != "1" &&
                                  _orderRefundStatus == "1") {
                                if (_deliveryType == "") {
                                  EasyLoading.showToast("请选择配送类型");
                                  return;
                                }
                                if (_refundType != "1" &&
                                    _deliveryType == "2" &&
                                    _selfOrderNo == '') {
                                  EasyLoading.showToast("请输入自配单号");
                                  return;
                                }
                                if (_refundType != "1" &&
                                    _deliveryType == "1") {
                                  if (_logisticCompanySn == "") {
                                    EasyLoading.showToast("请选择物流公司");
                                    return;
                                  }
                                  if (_logisticNumber == "") {
                                    EasyLoading.showToast("请填写物流单号");
                                    return;
                                  }
                                }
                                var index = tireSizes.value
                                    .indexWhere((element) => element == "");
                                if (index != -1) {
                                  EasyLoading.showToast("请填写完成胎码");
                                  return;
                                }
                              }
                              await doSupplyVerify(
                                  tireSize: tireSizes.value.join(","),
                                  deliveryType: _deliveryType,
                                  selfOrderNo: _selfOrderNo,
                                  logisticCompanySn: _logisticCompanySn,
                                  logisticNumber: _logisticNumber,
                                  refundOrderNo: _refundOrderNo,
                                  orderRefundStatus: _orderRefundStatus,
                                  refundImgUrl: _refundImgUrl,
                                  reviewRemark: _reviewRemark);
                              // onRefresh();
                              Get.back();
                              if (successFn != null) {
                                successFn();
                              }
                              // handleVisitorSeviceSubmit();
                              // Get.back();
                            },
                            colors: [Color(0xff0000f4), Color(0xff0000f4)]),
                      ))
                    ],
                  ),
                ),
                Container(
                  width: double.infinity,
                  height: screenBottomHeight,
                )
              ],
            ))),
      ));
}

//三包的售后处理
buildSbShHandle(
    {dynamic item,
    String ruleUrl = '',
    required Function doGetDict,
    required Function doSupplyVerify,
    Function? handleDetailApi,
    Function? threeSafeHandleApi,
    Function? successFn}) async {
  // EasyLoading.showToast("这里即将新做");

  //处理 方式
  var orderRefundStatus = [].obs;
  var orderRefundStatusList = [
    {"label": "受理", "value": "1"},
    {"label": "拒绝", "value": "2"}
  ].obs;
  //客服意见
  var reviewRemark = ''.obs;
  var refundImgUrl = [].obs;

  //配送类型
  var deliveryTypes = [].obs;
  //自配单号
  var selfOrderNo = "".obs;

  //物流公司
  var logisticCompanySn = [].obs;
  var logisticCompany = "".obs;
  var logisticCompanyList = [].obs;
  //物流单号

  var logisticNumber = ''.obs;
  //物流备注
  var remark = "".obs;

  var quantity = int.parse(showText(item["quantity"])) ?? 0;

  //残沟深 mm
  var badDepth = "".obs;
  //	故障原因 dict redund_err_reason
  var errReasonId = [].obs;
  var errReasonIdList = [].obs;
  // 初鉴判断 dict refund_judge_type
  var judgeId = "1".obs;
  var judgeIdList = [].obs;
  //处理结果 dict refund_handle_result
  var handleResultId = [].obs;
  //是否收取磨损
  var useReduceFlag = [].obs;
  //收取磨损 mm
  var useReduce = "".obs;
  //收取折旧费
  var useReduceFee = "".obs;
  //理赔金额
  var returnAmount = "".obs;
  // 价格差额
  var gapAmount = "".obs;

  var tireSizes = [].obs;
  for (var i = 0; i < quantity; i++) {
    tireSizes.value.add("");
  }
  //物流字典
  var l = await doGetDict(code: "logistic_company_type") as List;
  logisticCompanyList.value = l.map((e) {
        return {
          "label": showText(e["dictLabel"]),
          "value": showText(e["dictCode"])
        };
      }).toList() ??
      [];
  //初鉴判断
  var r = await doGetDict(code: "refund_judge_type") as List;
  judgeIdList.value = r.map((e) {
        return {
          "label": showText(e["dictLabel"]),
          "value": showText(e["dictValue"])
        };
      }).toList() ??
      [];
  //故障原因
  var er = await doGetDict(code: "redund_err_reason") as List;
  errReasonIdList.value = er.map((e) {
        return {
          "label": showText(e["dictLabel"]),
          "value": showText(e["dictValue"])
        };
      }).toList() ??
      [];
  var attrVo = {}.obs;
  var detail = {}.obs;
  if (handleDetailApi != null) {
    print("详情----111----");
    var dd =
        await handleDetailApi(refundOrderNo: showText(item["refundOrderNo"]));
    attrVo.value = dd["attrVo"] ?? {};

    detail.value = dd["detail"] ?? {};
    print("详情--------");
    print(attrVo.value);
  }
  refundTypeInputController.text = refundTypeName(showText(item["refundType"]));

  resetInput() {
    logisticNumber.value = "";
    for (var i = 0; i < tireSizes.value.length; i++) {
      tireSizes.value[i] = "";
    }
    useReduce.value = "";
    useReduceFee.value = "";
    returnAmount.value = "";
    gapAmount.value = "";

    useReduceInputController.text = "";
    selfOrderNoInputController.text = "";
    logisticNumberInputController.text = "";
    gapAmountInputController.text = "";
    returnAmountInputController.text = "";
    useReduceFeeInputController.text = "";
    tireSizesInputController.text = "";
    refundTypeInputController.text = "";
  }

  //  var screenBottomHeight =
  // double.parse(GlobalPrefs.getValue("screenBottomHeight"));
  var screenBottomHeight = MediaQuery.of(Get.overlayContext!).padding.bottom;
  Get.bottomSheet(
      isScrollControlled: true,
      Container(
        padding: EdgeInsets.only(left: 10, right: 10, top: 20),
        decoration: new BoxDecoration(
          color: Colors.white,
          // new Radius.circular(20.0)
          borderRadius: new BorderRadius.only(
              topLeft: new Radius.circular(20.0),
              topRight: new Radius.circular(20.0)), //圆角
        ),
        height: 700,
        child: Obx(() => Container(
            width: double.infinity,
            height: double.infinity,
            // color: Colors.red,
            child: Column(
              children: [
                Container(
                  width: double.infinity,
                  alignment: Alignment.center,
                  child: Text(
                    "售后处理",
                    style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                  ),
                ),
                Expanded(
                    child: Container(
                  width: double.infinity,
                  height: double.infinity,
                  color: Colors.white,
                  child: SingleChildScrollView(
                      child: Column(
                    children: [
                      Container(
                        width: double.infinity,
                        padding: EdgeInsets.only(
                            left: 10, bottom: 10, top: 10, right: 10),
                        child: Row(
                          children: [
                            Expanded(
                                child: Text(
                              "送鉴单位/人:" + showText(attrVo.value["userName"]),
                              style: TextStyle(fontSize: 18),
                            ))
                          ],
                        ),
                      ),
                      Container(
                        width: double.infinity,
                        padding: EdgeInsets.only(
                            left: 10, bottom: 10, top: 10, right: 10),
                        child: Row(
                          children: [
                            Expanded(
                                child: Text(
                              "电话:" + showText(attrVo.value["phone"]),
                              style: TextStyle(fontSize: 18),
                            ))
                          ],
                        ),
                      ),
                      Container(
                        width: double.infinity,
                        padding: EdgeInsets.only(
                            left: 10, bottom: 10, top: 10, right: 10),
                        child: Row(
                          children: [
                            Expanded(
                                child: Text(
                              "品牌:" + showText(attrVo.value["brandName"]),
                              style: TextStyle(fontSize: 18),
                            )),
                            Expanded(
                                child: Text(
                              "花纹:" + showText(attrVo.value["figuer"]),
                              style: TextStyle(fontSize: 18),
                            ))
                          ],
                        ),
                      ),
                      Container(
                        width: double.infinity,
                        padding: EdgeInsets.only(
                            left: 10, bottom: 10, top: 10, right: 10),
                        child: Row(
                          children: [
                            Expanded(
                                child: Text(
                              "型号:" + showText(attrVo.value["model"]),
                              style: TextStyle(fontSize: 18),
                            )),
                            Expanded(
                                child: Text(
                              "层级:" + showText(attrVo.value["productLevel"]),
                              style: TextStyle(fontSize: 18),
                            ))
                          ],
                        ),
                      ),
                      Container(
                        width: double.infinity,
                        padding: EdgeInsets.only(
                            left: 10, bottom: 10, top: 10, right: 10),
                        child: Row(
                          children: [
                            Expanded(
                                child: Text(
                              "胎号:" + showText(attrVo.value["tireSize"]),
                              style: TextStyle(fontSize: 18),
                            ))
                          ],
                        ),
                      ),
                      Container(
                        width: double.infinity,
                        padding: EdgeInsets.only(
                            left: 10, bottom: 10, top: 10, right: 10),
                        child: Row(
                          children: [
                            Expanded(
                                child: Text(
                              "原胎深:" + showText(attrVo.value["figuerDeep"]),
                              style: TextStyle(fontSize: 18),
                            ))
                          ],
                        ),
                      ),

                      Container(
                        width: double.infinity,
                        padding: EdgeInsets.only(
                            left: 10, bottom: 10, top: 10, right: 10),
                        child: Row(
                          children: [
                            Container(
                                child: Text(
                              "年号:",
                              style: TextStyle(fontSize: 18),
                            )),
                            Expanded(
                                child: Container(
                                    width: double.infinity,
                                    // height: 100,
                                    child: Wrap(
                                        spacing: 0, //主轴上子控件的间距
                                        runSpacing: 0,
                                        children: [
                                          ...splitImgUrl(showText(attrVo
                                                  .value["yearWeekNumUrl"]))
                                              .map((u) {
                                            return FractionallySizedBox(
                                                widthFactor: 1 / 2,
                                                child: Container(
                                                  height: 100,
                                                  child: buildImage(
                                                      fit: BoxFit.fitHeight,
                                                      provider: true,
                                                      type: "ClipRect",
                                                      url: showText(attrVo
                                                              .value[
                                                          "yearWeekNumUrl"])),
                                                ));
                                          }).toList()
                                        ])))
                          ],
                        ),
                      ),
                      buildInput(
                          required: true,
                          title: "残沟深",
                          unit: "mm",
                          value: badDepth.value,
                          labelWidth: 130,
                          onChanged: (v) {
                            badDepth.value = v;
                          }),
                      buildSelect(
                          required: true,
                          title: "故障原因",
                          value: errReasonId.value,
                          onChanged: (v, n) {
                            errReasonId.value = v;
                            // orderRefundStatus.value = v;
                          },
                          multiple: false,
                          list: [...errReasonIdList.value]),

                      buildRadio(
                          required: true,
                          title: "初鉴判断",
                          value: judgeId.value,
                          widthFactor: 1,
                          list: [
                            ...judgeIdList.value
                            // {"label": " 质量问题制造方责任", "value": "0"},
                            // {"label": "使用问题使用方责任", "value": "1"},
                          ],
                          onChanged: (v) {
                            judgeId.value = v;
                            handleResultId.value = [];
                            resetInput();
                          }),

                      buildSelect(
                          required: true,
                          title: "处理结果",
                          value: handleResultId.value,
                          onChanged: (v, n) {
                            handleResultId.value = v;
                            resetInput();
                          },
                          multiple: false,
                          list: [
                            {
                              "label": "正常理赔",
                              "value": "1",
                              "hidden": !(showText(judgeId.value) == '1')
                            },
                            {
                              "label": "不予理赔",
                              "value": "2",
                              "hidden": !(showText(judgeId.value) == '2')
                            },
                            {
                              "label": "商务照顾理赔",
                              "value": "3",
                              "hidden": !(showText(judgeId.value) == '2')
                            },
                          ]),

                      //显示条件：质量问题制造方责任、正常理赔
                      Visibility(
                          visible: showText(judgeId.value) == '1' &&
                              handleResultId.value.contains("1"),
                          child: buildSelect(
                              required: true,
                              title: "是否收取磨损",
                              labelWidth: 160,
                              value: useReduceFlag.value,
                              onChanged: (v, n) {
                                useReduceFlag.value = v;
                              },
                              multiple: false,
                              list: [
                                {"label": "收取磨损", "value": "1"},
                                {"label": "不收取磨损", "value": "2"},
                              ])),
                      //显示条件：质量问题制造方责任、正常理赔、收取磨损
                      Visibility(
                        visible: showText(judgeId.value) == '1' &&
                            useReduceFlag.value.contains('1') &&
                            handleResultId.value.contains("1"),
                        child: buildInput(
                            required: false,
                            title: "收取磨损/折旧费",
                            unit: "mm",
                            textEditingController: useReduceInputController,
                            labelWidth: 160,
                            onChanged: (v) {
                              useReduce.value = v;
                            }),
                      ),
                      Visibility(
                          visible: showText(judgeId.value) == '1' &&
                              useReduceFlag.value.contains('1') &&
                              handleResultId.value.contains("1"),
                          child: buildInput(
                              required: false,
                              title: "",
                              unit: "元",
                              labelWidth: 130,
                              textEditingController:
                                  useReduceFeeInputController,
                              onChanged: (v) {
                                useReduceFee.value = v;
                              })),
                      //显示条件：使用问题使用方责任、商务照顾理赔
                      Visibility(
                          visible: showText(judgeId.value) == '2' &&
                              handleResultId.value.contains('3'),
                          child: buildInput(
                              required: false,
                              title: "理赔金额",
                              unit: "元",
                              textEditingController:
                                  returnAmountInputController,
                              labelWidth: 160,
                              onChanged: (v) {
                                returnAmount.value = v;
                              })),
                      //显示条件：使用问题使用方责任、商务照顾理赔
                      Visibility(
                          visible: showText(judgeId.value) == '2' &&
                              handleResultId.value.contains('3'),
                          child: buildInput(
                              required: false,
                              title: "价格差额",
                              unit: "元",
                              textEditingController: gapAmountInputController,
                              labelWidth: 160,
                              onChanged: (v) {
                                gapAmount.value = v;
                              })),
                      // buildInput(
                      //     required: false,
                      //     title: "申请类型",
                      //     disabled: true,
                      //     textEditingController: refundTypeInputController,
                      //     labelWidth: 130,
                      //     value: refundTypeName(showText(item["refundType"])),
                      //     onChanged: (v, n) {
                      //       // orderRefundStatus.value = v;
                      //     }),
                      // buildSelect(
                      //     required: true,
                      //     title: "处理方式",
                      //     value: orderRefundStatus.value,
                      //     onChanged: (v, n) {
                      //       orderRefundStatus.value = v;
                      //     },
                      //     multiple: false,
                      //     list: orderRefundStatusList.value),

                      // Visibility(
                      //     visible: showText(item["refundType"]) != "1" &&
                      //         orderRefundStatus.value.join(",") != "2",
                      //     child:

                      Visibility(
                          visible: handleResultId.value.contains("2") &&
                              showText(detail["returnFlag"]) == '1',
                          child: buildSelect(
                              required: true,
                              title: "物流公司",
                              value: logisticCompanySn.value,
                              onChanged: (v, n) {
                                logisticCompanySn.value = v;
                                logisticCompany.value = n;
                              },
                              multiple: false,
                              list: logisticCompanyList)),
                      // ),

                      // Visibility(
                      //   visible: showText(item["refundType"]) != "1" &&
                      //       orderRefundStatus.value.join(",") != "2",
                      //   child:
                      Visibility(
                          visible: handleResultId.value.contains("2") &&
                              showText(detail["returnFlag"]) == '1',
                          child: buildInput(
                              required: true,
                              title: "物流单号",
                              value: logisticNumber.value,
                              textEditingController:
                                  logisticNumberInputController,
                              onChanged: (v) {
                                logisticNumber.value = v;
                              })
                          // ),
                          ),

                      //显示条件：使用问题使用方责任、不包含（不予理赔）
                      Visibility(
                          visible: !(showText(judgeId.value) == '2' &&
                              handleResultId.value.contains('2')),
                          child: Column(
                            children: [
                              buildSelect(
                                  required: true,
                                  title: "配送类型",
                                  value: deliveryTypes.value,
                                  onChanged: (v, n) {
                                    deliveryTypes.value = v;
                                  },
                                  multiple: false,
                                  list: [
                                    {"value": "1", "label": "物流"},
                                    {"value": "2", "label": "自配"}
                                  ]),
                              // ),
                              // Visibility(
                              //     visible: showText(item["refundType"]) != "1" &&
                              //         orderRefundStatus.value.join(",") != "2",
                              //     child:
                              Visibility(
                                  visible: deliveryTypes.value.join(",") == '2',
                                  child: buildInput(
                                      required: true,
                                      title: "自配单号",
                                      value: selfOrderNo.value,
                                      textEditingController:
                                          selfOrderNoInputController,
                                      onChanged: (v) {
                                        selfOrderNo.value = v;
                                      })),
                              // ),

                              // Visibility(
                              //     visible: showText(item["refundType"]) != "1" &&
                              //         orderRefundStatus.value.join(",") != "2",
                              //     child:

                              Visibility(
                                  visible:
                                      deliveryTypes.value.join(",") == '1' ||
                                          handleResultId.value.contains("2"),
                                  child: buildSelect(
                                      required: true,
                                      title: "物流公司",
                                      value: logisticCompanySn.value,
                                      onChanged: (v, n) {
                                        logisticCompanySn.value = v;
                                        logisticCompany.value = n;
                                      },
                                      multiple: false,
                                      list: logisticCompanyList)),
                              // ),

                              // Visibility(
                              //   visible: showText(item["refundType"]) != "1" &&
                              //       orderRefundStatus.value.join(",") != "2",
                              //   child:
                              Visibility(
                                  visible:
                                      deliveryTypes.value.join(",") == '1' ||
                                          handleResultId.value.contains("2"),
                                  child: buildInput(
                                      required: true,
                                      title: "物流单号",
                                      textEditingController:
                                          logisticNumberInputController,
                                      value: logisticNumber.value,
                                      onChanged: (v) {
                                        logisticNumber.value = v;
                                      })
                                  // ),
                                  ),

                              ...tireSizes.value.asMap().keys.map((i) {
                                return Visibility(
                                    visible:
                                        showText(item["refundType"]) != "1" &&
                                            orderRefundStatus.value.join(",") !=
                                                "2",
                                    child: buildInput(
                                        required: true,
                                        height: 120,
                                        labelHeight: 50,
                                        title: "胎码",
                                        value: tireSizes.value[i],
                                        type: "textArea",
                                        textEditingController:
                                            tireSizesInputController,
                                        direction: "ttb",
                                        inputFormatters: [
                                          FilteringTextInputFormatter.deny(
                                              RegExp(',')),
                                          FilteringTextInputFormatter.deny(
                                              RegExp('，'))
                                        ],
                                        placeholder: "请输入胎码",
                                        onChanged: (v) {
                                          tireSizes.value[i] = v;
                                          // state.tireSizes.value[i] = v;
                                        }));
                              }).toList(),

                              buildInput(
                                  title: "客服意见",
                                  labelHeight: 50,
                                  height: 180,
                                  type: "textArea",
                                  maxLines: 3,
                                  direction: "ttb",
                                  value: reviewRemark.value,
                                  onChanged: (v) {
                                    reviewRemark.value = v;
                                  }),
                              // Container(
                              //   width: double.infinity,
                              //   height: 50,
                              //   alignment: Alignment.centerLeft,
                              //   padding: EdgeInsets.only(left: 10),
                              //   child: Text(
                              //     "处理结果",
                              //     style: TextStyle(fontSize: 18),
                              //   ),
                              // ),

                              // buildUpload(
                              //     list: refundImgUrl,
                              //     rowCount: 2,
                              //     max: 4,
                              //     onChange: (type, value, index) {
                              //       if (type == 'add') {
                              //         print("添加返回");

                              //         refundImgUrl.add(value);
                              //       }
                              //       if (type == 'del') {
                              //         refundImgUrl.removeAt(index);
                              //       }
                              //       if (type == 'change') {
                              //         refundImgUrl[index] = value;
                              //       }
                              //     }),
                            ],
                          ))
                    ],
                  )),
                )),
                GestureDetector(
                  onTap: () {
                    Get.toNamed("/webview",
                        arguments: {"title": "《理赔标准》", "url": ruleUrl});
                  },
                  child: Container(
                    width: double.infinity,
                    height: 50,
                    alignment: Alignment.topCenter,
                    child: Text(
                      "《理赔标准》",
                      style: TextStyle(fontSize: 25, color: Color(0xff0000e9)),
                    ),
                    color: Colors.transparent,
                  ),
                ),
                Container(
                  width: double.infinity,
                  height: 80,
                  color: Colors.white,
                  child: Row(
                    children: [
                      Expanded(
                          child: Container(
                        width: double.maxFinite,
                        height: double.infinity,
                        color: Colors.white,
                        padding: EdgeInsets.only(
                            top: 10, bottom: 10, left: 10, right: 10),
                        child: buildButton(
                            title: "确定",
                            onClick: () async {
                              var _refundOrderNo =
                                  showText(item["refundOrderNo"]);

                              // 残沟深
                              var _badDepth = badDepth.value;
                              //故障原因
                              var _errReasonId = errReasonId.value.join("");
                              //初鉴判断
                              var _judgeId = judgeId.value;
                              //处理结果
                              var _handleResultId =
                                  handleResultId.value.join("");
                              //是否收取磨损
                              var _useReduceFlag = useReduceFlag.value.join("");
                              //收取磨损
                              var _useReduce = useReduce.value;
                              //收取折旧费
                              var _useReduceFee = useReduceFee.value;
                              //理赔金额
                              var _returnAmount = returnAmount.value;
                              //价格差额
                              var _gapAmount = gapAmount.value;
                              // 配送类型
                              var _deliveryType = deliveryTypes.value.join("");

                              // var _orderRefundStatus =
                              //     orderRefundStatus.value.join(",");
                              var _reviewRemark = reviewRemark.value;

                              var _refundImgUrl = refundImgUrl.value.join(",");

                              var _selfOrderNo = selfOrderNo.value;

                              var _logisticNumber = logisticNumber.value;
                              var _logisticCompanySn =
                                  logisticCompanySn.value.join("");

                              if (_badDepth.isEmpty) {
                                EasyLoading.showToast("请输入残沟深");
                                return;
                              }

                              if (_errReasonId.isEmpty) {
                                EasyLoading.showToast("请选择故障原因");
                                return;
                              }

                              if (_handleResultId.isEmpty) {
                                EasyLoading.showToast("请选择处理结果");
                                return;
                              }

                              //如果处理结果为正常理赔，需要检测是否收取磨损
                              if (_handleResultId.contains("1")) {
                                if (_useReduceFlag.isEmpty) {
                                  EasyLoading.showToast("请选择是否收取磨损");
                                  return;
                                }

                                // 如果收取磨损
                                if (_useReduceFlag.contains("1")) {
                                  if (_useReduce.isEmpty) {
                                    EasyLoading.showToast("请输入磨损");
                                    return;
                                  }

                                  if (useReduceFee.isEmpty) {
                                    EasyLoading.showToast("请输入折旧费");
                                    return;
                                  }
                                }
                              }

                              if (_judgeId == "2" && _handleResultId == "3") {
                                if (_returnAmount.isEmpty) {
                                  EasyLoading.showToast("请输入理赔金额");
                                  return;
                                }

                                if (_gapAmount.isEmpty) {
                                  EasyLoading.showToast("请输入价格差额");
                                  return;
                                }
                              }

                              //如果处理结果非  不予理赔，需要检测
                              if (!(_judgeId == "2" &&
                                  _handleResultId == "2")) {
                                //检测配送类型
                                if (_deliveryType == "") {
                                  EasyLoading.showToast("请选择配送类型");
                                  return;
                                }
                                if (_deliveryType == "2" &&
                                    _selfOrderNo == '') {
                                  EasyLoading.showToast("请输入自配单号");
                                  return;
                                }
                                if (_deliveryType == "1") {
                                  if (_logisticCompanySn == "") {
                                    EasyLoading.showToast("请选择物流公司");
                                    return;
                                  }
                                  if (_logisticNumber == "") {
                                    EasyLoading.showToast("请填写物流单号");
                                    return;
                                  }
                                }
                                var index = tireSizes.value
                                    .indexWhere((element) => element == "");
                                if (index != -1) {
                                  EasyLoading.showToast("请填写完成胎码");
                                  return;
                                }
                              }

                              //不予理赔
                              if (_judgeId == "2" && _handleResultId == "2") {
                                if (showText(detail["returnFlag"]) == '1') {
                                  if (_logisticCompanySn == "") {
                                    EasyLoading.showToast("请选择物流公司");
                                    return;
                                  }
                                  if (_logisticNumber == "") {
                                    EasyLoading.showToast("请填写物流单号");
                                    return;
                                  }
                                }
                              }

                              // var _orderRefundStatus =
                              //     orderRefundStatus.value.join(",");
                              // var _reviewRemark = reviewRemark.value;

                              // var _refundImgUrl = refundImgUrl.value.join(",");

                              // var _deliveryType = deliveryTypes.value.join("");
                              // var _selfOrderNo = selfOrderNo.value;

                              // var _logisticNumber = logisticNumber.value;
                              // var _logisticCompanySn =
                              //     logisticCompanySn.value.join("");

                              // var _refundType = showText(item["refundType"]);

                              // if (_orderRefundStatus == '') {
                              //   EasyLoading.showToast("请选择处理方式");
                              //   return;
                              // }

                              // if (_refundType != "1" &&
                              //     _orderRefundStatus == "1") {
                              //   if (_deliveryType == "") {
                              //     EasyLoading.showToast("请选择配送类型");
                              //     return;
                              //   }
                              //   if (_refundType != "1" &&
                              //       _deliveryType == "2" &&
                              //       _selfOrderNo == '') {
                              //     EasyLoading.showToast("请输入自配单号");
                              //     return;
                              //   }
                              //   if (_refundType != "1" &&
                              //       _deliveryType == "1") {
                              //     if (_logisticCompanySn == "") {
                              //       EasyLoading.showToast("请选择物流公司");
                              //       return;
                              //     }
                              //     if (_logisticNumber == "") {
                              //       EasyLoading.showToast("请填写物流单号");
                              //       return;
                              //     }
                              //   }
                              //   var index = tireSizes.value
                              //       .indexWhere((element) => element == "");
                              //   if (index != -1) {
                              //     EasyLoading.showToast("请填写完成胎码");
                              //     return;
                              //   }
                              // }

                              if (threeSafeHandleApi == null) {
                                EasyLoading.showToast("缺少提交api");
                                return;
                              }

                              print("提交======");
                              print(threeSafeHandleApi);
                              // print({
                              //   "badDepth": _badDepth,
                              //   "errReasonId": _errReasonId,
                              //   "gapAmount": _gapAmount,
                              //   "handleResultId": _handleResultId,
                              //   "judgeId": _judgeId,
                              //   "logisticCompany": _logisticCompanySn,
                              //   "logisticNo": _logisticNumber,
                              //   "refundOrderNo": _refundOrderNo,
                              //   "returnAmount": _returnAmount,
                              //   "useReduce": _useReduce,
                              //   "useReduceFee": _useReduceFee,
                              //   "useReduceFlag": _useReduceFlag,
                              // });

                              await threeSafeHandleApi(
                                badDepth: _badDepth,
                                errReasonId: _errReasonId,
                                gapAmount: _gapAmount,
                                handleResultId: _handleResultId,
                                judgeId: _judgeId,
                                logisticCompanySn: _logisticCompanySn,
                                logisticNumber: _logisticNumber,
                                refundOrderNo: _refundOrderNo,
                                returnAmount: _returnAmount,
                                useReduce: _useReduce,
                                useReduceFee: _useReduceFee,
                                useReduceFlag: _useReduceFlag,
                                //
                                tireSize: tireSizes.value.join(","),
                                deliveryType: _deliveryType,
                                selfOrderNo: _selfOrderNo,
                              );

                              // refundImgUrl: _refundImgUrl,
                              // reviewRemark: _reviewRemark
                              // onRefresh();

                              // return;
                              Get.back();
                              if (successFn != null) {
                                successFn();
                              }
                            },
                            colors: [Color(0xff0000f4), Color(0xff0000f4)]),
                      ))
                    ],
                  ),
                ),
                Container(
                  width: double.infinity,
                  height: screenBottomHeight,
                )
              ],
            ))),
      ));
}

List splitImgUrl(String s) {
  return s.split(",") ?? [];
}
